<?php

class SON_Plugins_Placeholders_Welcome extends Zend_Controller_Plugin_Abstract
{
    public function dispatchLoopStartup(Zend_Controller_Request_Abstract $request)
    {
        $viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer');
        $viewRenderer->initView();
        $view = $viewRenderer->view;

        $auth = Zend_Auth::getInstance ();
        $auth->setStorage(new Zend_Auth_Storage_Session('default'));

        if ($auth->hasIdentity()) {
            $content = '<li><a href="' . $view->url(array('module' => 'default', 'controller' => 'auth', 'action' => 'logout'), null, true) . '">Logout</a></li>';
        } else {
            $content = '<li><a href="' . $view->url(array('module' => 'default', 'controller' => 'conta', 'action' => 'cadastro'), null, true) . '">Cadastro</a></li>';
			$content .= '<li><a href="' . $view->url(array('module' => 'default', 'controller' => 'auth'), null, true) . '">Login</a></li>';
        }
        $view->placeholder('welcome')->append($content);
    }
}